package com.surprise.biz.bo.serializer;

import org.springframework.stereotype.Component;

import com.surprise.base.util.JacksonUtils;

/**
 * JsonMessageSerializer.java
 * @author nick
 * 2015年2月13日
 */
@Component
public class JsonMessageSerializer implements MessageSerializer {

    @Override
    public String serialize(Object o) {
        return JacksonUtils.toJson(o);
    }

    @Override
    public <T> T deserialize(String s, Class<T> clazz) {
        return JacksonUtils.fromJson(s, clazz);
    }

    @Override
    public byte[] serializeBits(Object o) {
        String json = serialize(o);
        return json.getBytes();
    }

    @Override
    public <T> T deserializeBits(byte[] bs, Class<T> clazz) {
        String json = new String(bs);
        return deserialize(json, clazz);
    }

}
